/****************************************************************************
**
** Copyright (C) 2010 Tieto Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Tieto Corporation (info.ostrava@tieto.com)
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Tieto.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Tieto gives you certain additional
** rights.  These rights are described in the Tieto Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you have questions regarding the use of this file, please contact
** Tieto at info.ostrava@tieto.com.
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtGui/QColor>

#include "image.h"

#define ALPHA_MASK 0xFF000000
#define BINARY_MASK 0x00000001

ColorImage::ColorImage()
{

}

ColorImage::ColorImage(const QSize & size)
    : QImage(size, QImage::Format_RGB32)
{
    fill(QColor(Qt::white).rgb());
}

ColorImage::ColorImage(int width, int height)
    : QImage(width, height, QImage::Format_RGB32)
{
    fill(QColor(Qt::transparent).rgb());
}

ColorImage &ColorImage::operator=(const QImage &image)
{
    QImage &self = *this;
    return (ColorImage&)(self = image);
}

GrayscaleImage::GrayscaleImage()
{

}

GrayscaleImage::GrayscaleImage(const QSize & size)
    : ColorImage(size)
{

}

GrayscaleImage::GrayscaleImage(int width, int height)
    : ColorImage(width, height)
{

}

Grayscale GrayscaleImage::grayscale(int x, int y) const
{
    return (Grayscale)(ColorImage::pixel(x, y));
}

void GrayscaleImage::setGrayscale(int x, int y, Grayscale gray)
{
    QColor color(gray, gray, gray);
    QRgb rgb = color.rgb();
    ColorImage::setPixel(x, y, rgb);
}

GrayscaleImage &GrayscaleImage::operator=(const QImage &image)
{
    ColorImage &self = *this;
    return (GrayscaleImage&)(self = image);
}

QRgb GrayscaleImage::pixel(int x, int y) const
{
    return QRgb();
}

QRgb GrayscaleImage::pixel(const QPoint &pt) const
{
    return QRgb();
}

void GrayscaleImage::setPixel(int x, int y, uint index_or_rgb)
{

}

void GrayscaleImage::setPixel(const QPoint &pt, uint index_or_rgb)
{

}

BinaryImage::BinaryImage()
{

}

BinaryImage::BinaryImage(const QSize & size)
    : ColorImage(size)
{

}

BinaryImage::BinaryImage(int width, int height)
    : ColorImage(width, height)
{

}

BinaryColor BinaryImage::binaryColor(int x, int y) const
{
    QRgb pixel = ColorImage::pixel(x, y);
    BinaryColor color = (pixel == Qt::black) ? Black : White;
    return color;
}

void BinaryImage::setBinaryColor(int x, int y, BinaryColor color)
{
    QRgb rgb;
    if (color == Black) {
        rgb = QColor(Qt::black).rgb();
    }
    else {
        rgb = QColor(Qt::white).rgb();
    }
    ColorImage::setPixel(x, y, rgb);    
}

BinaryImage &BinaryImage::operator=(const QImage &image)
{
    ColorImage &self = *this;
    return (BinaryImage&)(self = image);
}

QRgb BinaryImage::pixel(int x, int y) const
{
    return QRgb();
}

QRgb BinaryImage::pixel(const QPoint &pt) const
{
    return QRgb();
}

void BinaryImage::setPixel(int x, int y, uint index_or_rgb)
{

}

void BinaryImage::setPixel(const QPoint &pt, uint index_or_rgb)
{

}

IndexImage::IndexImage() :
    _indexCount(0)
{

}

IndexImage::IndexImage(const QSize & size)
    : ColorImage(size)
{
    fill(0); // TODO
}

IndexImage::IndexImage(int width, int height)
    : ColorImage(width, height)
{
    fill(0); // TODO
}

uint IndexImage::index(int x, int y) const
{
    return (~ALPHA_MASK & ColorImage::pixel(x, y));
}

void IndexImage::setIndex(int x, int y, uint index)
{
    ColorImage::setPixel(x, y, index);
}

void IndexImage::setIndexCount(int count)
{
    _indexCount = count;
}

int IndexImage::indexCount() const
{
    return _indexCount;
}

IndexImage &IndexImage::operator=(const QImage &image)
{
    ColorImage &self = *this;
    return (IndexImage&)(self = image);
}

QRgb IndexImage::pixel(int x, int y) const
{
    return QRgb();
}

QRgb IndexImage::pixel(const QPoint &pt) const
{
    return QRgb();
}

void IndexImage::setPixel(int x, int y, uint index_or_rgb)
{

}

void IndexImage::setPixel(const QPoint &pt, uint index_or_rgb)
{

}

/* TODO
IndexedArea::IndexedArea() {

}

void IndexedArea::operator =(const IndexedArea &areas)
{
    *this = areas;
}

void IndexedArea::operator=(const BinaryImage &data)
{
    _data = data.copy();
}

void IndexedArea::operator=(const ColorImage &image)
{
    _image = image.copy();
}
*/
